package com.kmair.caiwu.controller.activiti.Identity;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
@RequestMapping("/users")
public class UserController {

    final IdentityService identityService;

    @Autowired
    public UserController(IdentityService identityService) {
        this.identityService = identityService;
    }

    @RequestMapping(method = RequestMethod.GET, produces = "text/html")
    public String showUsers(Model model) {
        List<User> userList = getUsers();
        model.addAttribute(userList);
        return "identity/user_management";
    }

    public List<User> getUsers() {
        return identityService.createUserQuery().list();
    }
}
